<?php
require_once 'Junction/Builder.php';
require_once 'Junction/Mapping.php';
require_once 'Junction/Utils/Config.php';

class Junction_Core_Factory {
    
    private static $_mappings = array();
    
    private static function getMappingForObject($object) {
        return self::getMappingForClassname(get_class($object));
    }
    
    private static function getMappingForClassname($classname) {
        if (!isset(self::$_mappings[$classname])) {
            $conf = Junction_Utils_Config::getSingleton();
    		$mappingFile = $conf->read('schema_location') . $conf->read($classname);
    		self::$_mappings[$classname] = Junction_Builder::buildMapping($mappingFile);
        }
        return self::$_mappings[$classname];
    }
	
	/**
	 * @param Object|String $class
	 * @return Junction_Mapping
	 */
	public static function construct($class) {
		if (is_object($class)) {
		    return self::getMappingForObject($class);
		}
		return self::getMappingForClassname($class);
	}
}
?>